package com.example.day1_dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

//TODO 1：自定义类继承Dialog，重写所有构造
public class YaoDialog extends Dialog {
    //TODO 2：定义成员变量，对话框中的内容
    private Button bt_yes,bt_no;
    private TextView tv_title,tv_message;
    private String yesStr,noStr,titleStr,messageStr;

    private YaoListener yesListener,noListener;//2个按钮的监听

    public YaoDialog setYesListener(YaoListener yesListener) {
        this.yesListener = yesListener;
        return this;
    }

    public YaoDialog setNoListener(YaoListener noListener) {
        this.noListener = noListener;
        return this;
    }

    //TODO 4:为String类型提供get和set方法


    public  YaoDialog setYesStr(String yesStr) {
        this.yesStr = yesStr;
        return this;
    }



    public YaoDialog setNoStr(String noStr) {
        this.noStr = noStr;
        return this;
    }



    public YaoDialog setTitleStr(String titleStr) {
        this.titleStr = titleStr;
        return this;
    }



    public YaoDialog setMessageStr(String messageStr) {
        this.messageStr = messageStr;
        return this;
    }

    public YaoDialog(@NonNull Context context) {
        super(context);
    }

    public YaoDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
    }

    protected YaoDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
    }

    //TODO 3:重写oncreate方法，当被创建的时候，我们要加载布局并显示内容
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //加载布局
        setContentView(R.layout.dialog_diy);
        bt_yes = findViewById(R.id.yes);
        bt_no = findViewById(R.id.no);
        tv_title = findViewById(R.id.title);
        tv_message = findViewById(R.id.message);
        //显示内容
        bt_yes.setText(yesStr);
        bt_no.setText(noStr);
        tv_message.setText(messageStr);
        tv_title.setText(titleStr);
        //设置监听,不能做具体的处理:使用接口回调給activity中去处理
        bt_yes.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                yesListener.onClick();

            }
        });
        bt_no.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                noListener.onClick();

            }
        });



    }
    //接口回调
    interface YaoListener{
        void onClick();
    }


}
